rm(list = setdiff(ls(), lsf.str()))

# SI A.15
load("Study 2/data_trump.RData")

#Fit measures for agreeableness (Appendix) ----------------------------------------------------------------
#fit 
CFA_agree <-'Agree = ~ NA*Agre_2_rec + Agre_4_rec + Agre_6_rec + Agre_8_rec + Agre_10_rec + Q150_1 + Q150_3 + Q150_5 + Q150_7 + Q150_9
Agree ~~ 1*Agree' 

#assess fit
fit<-cfa(CFA_agree, ordered=c(data_trump$Agre_2_rec, data_trump$Agre_4_rec, data_trump$Agre_6_rec, data_trump$Agre_8_rec, data_trump$Agre10, data_trump$Q150_1, data_trump$Q150_3, data_trump$Q150_5, data_trump$Q150_7, data_trump$Q150_9), data=data_trump)
summary(fit, standardized=T)

parameterEstimates(fit, standardized=TRUE)
p<-parameterEstimates(fit, standardized=TRUE) %>%  dplyr::select(std.all, pvalue)
p <- p[-c(11:32), ] 
names(p) <- c("Standardized Factor Loading", "p-value")
p<-xtable(caption = "Agreeableness: Standardized Factor Loadings", label = "tab:SSI_cfa", p)
print(p, type="latex", file="Tables/SSI_agree_cfa.tex", caption.placement="top")

#Descriptive statistics----------------

#Alpha 10 item Agreebaleness scale == 0.76
alpha_Agre<-psych::alpha(data.frame(data_trump$Agre_2_rec, data_trump$Agre_4_rec, data_trump$Agre_6_rec, data_trump$Agre_8_rec, data_trump$Agre_10_rec, as.numeric(data_trump$Q150_1), as.numeric(data_trump$Q150_3), as.numeric(data_trump$Q150_5), as.numeric(data_trump$Q150_7), as.numeric(data_trump$Q150_9)))

#Alpha Authoritarianism == 0.76
alpha_auth<-psych::alpha(data.frame(data_trump$auth_1, data_trump$auth_2, data_trump$auth_3, data_trump$auth_4))

#Education
table(as.numeric(data_trump$education))

#Income
median(as.numeric(data_trump$income), na.rm=T)
mean(as.numeric(data_trump$income), na.rm=T)
sd(as.numeric(data_trump$income), na.rm=T)

#Race
table(as.numeric(data_trump$race))

#Partisanship
summary(data_trump$partyidentity)
sd(data_trump$partyidentity, na.rm=T)

